{% extends "users/settings/base.html" %}

{% block title %}
  基本信息
{% endblock %}

{% block edit %}
  <div class="row">
    <div class="col-sm-8 settings-content">
      <form class="form-horizontal" role="form" action="{% url 'users:base-information' request.user.id %}" method="post">
        <!--防止恶意攻击-->
        {% csrf_token %}
        <!--性别-->
        <div class="form-group">
          <label class="col-sm-2 control-label">性别：</label>
          <div class="col-sm-10">
            <label class="radio-inline">
              {% if user.sex == 1 %}
                <input type="radio" name="sex" value="1" checked/>男
              {% else %}
                <input type="radio" name="sex" value="1"/>男
              {% endif %}
            </label>
            <label class="radio-inline">
              {% if user.sex == 2 %}
                <input type="radio" name="sex" value="2" checked/>女
              {% else %}
                <input type="radio" name="sex" value="2"/>女
              {% endif %}
            </label>
            <label class="radio-inline">
              {% if user.sex == 0 %}
                <input type="radio" name="sex" value="0" checked/>保密
              {% else %}
                <input type="radio" name="sex" value="0"/>保密
              {% endif %}
            </label>
          </div>
        </div>
        <br/>
        <!--学校-->
        <div class="form-group">
          <label class="col-sm-2 control-label">学校：</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" name="school" value="{{ user.school }}" placeholder="没有在读学校可以不填"/>
            {% if school_error %}
              <p class="text-danger small">*{{ school_error }}</p>
            {% endif %}
          </div>
        </div>
        <br/>
        <!--公司-->
        <div class="form-group">
          <label class="col-sm-2 control-label">公司：</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" name="company" value="{{ user.company }}" placeholder="没有公司可以不填"/>
            {% if company_error %}
              <p class="text-danger small">*{{ company_error }}</p>
            {% endif %}
          </div>
        </div>
        <br/>
        <!--职业-->
        <div class="form-group">
          <label class="col-sm-2 control-label">职业：</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" name="profession" value="{{ user.profession }}" placeholder="没有职业可以不填"/>
            {% if profession_error %}
              <p class="text-danger small">*{{ profession_error }}</p>
            {% endif %}
          </div>
        </div>
        <br/>
        <!--生日-->
        <div class="form-group">
          <label class="col-sm-2 control-label">生日：</label>
          <div class="col-sm-10">
            {% if user.birthday %}
              <input type="date" class="form-control" style="line-height: unset" name="birthday" value="{{ user.birthday|date:'Y-m-d' }}"/>
            {% else %}
              <input type="date" class="form-control" style="line-height: unset" name="birthday" value="{{ user.date_joined|date:'Y-m-d' }}"/>
            {% endif %}
          </div>
        </div>
        <hr/>
        <!--保存按钮-->
        <button type="submit" class="btn btn-primary pull-right visible-sm visible-md visible-lg" onclick="save();">保存</button>
        <button type="submit" class="btn btn-primary btn-block visible-xs" onclick="save();">保存</button>
      </form>
    </div>
  </div>
  <script>
    function save(){
        // 用于日期格式控制，如果没有填写日期，则将日期设置为用户创建时间
        var birthdays = document.getElementsByName('birthday');
        for (var i = 0; i < birthdays.length; ++i) {
            if (birthdays[i].value.length === 0) {
                birthdays[i].value = "{{ user.date_joined|date:'Y-m-d' }}";
            }
        }
    }
  </script>
{% endblock %}